package com.telit.android.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.telit.android.dto.AppHotportTypeDto;
import com.telit.android.entity.AppTaskType;
import com.telit.android.service.IAppTaskTypeService;
import com.telit.common.entity.DataReturn;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * 任务类型 前端控制器
 * </p>
 *
 * @author yummy
 * @since 2021-07-22
 */
@RestController
@RequestMapping("/app-task-type")
@Api(tags = "任务类型", description = "/app-task-type")
public class AppTaskTypeController {

    private Logger log = LoggerFactory.getLogger(getClass());

    @Resource
    private IAppTaskTypeService appTaskTypeService;

    /*@PostMapping("/add")
    @ApiOperation("添加")
    public DataReturn add(@RequestBody AppTaskType appTaskType){
         int value= appTaskTypeService.add(appTaskType);
         return DataReturn.ok(value);
    }*/

    @GetMapping("/delete/{id}")
    @ApiImplicitParam(name = "id", value = "配置ID", paramType = "path", dataType = "Integer")
    public DataReturn delete(@PathVariable("id") Integer id) {
        int value = appTaskTypeService.delete(id);
        return DataReturn.ok(value);
    }

    @GetMapping("/deleteBatch")
    @ApiImplicitParam(name = "ids", value = "配置ID数组", paramType = "query", dataType = "integer[]")
    public DataReturn deleteBatch(Integer[] ids) {
        List<Integer> values = appTaskTypeService.deleteBatch(ids);
        return DataReturn.ok(values);
    }

    @PostMapping("/update")
    @ApiOperation("修改")
    public DataReturn update(@RequestBody AppTaskType appTaskType) {
        appTaskTypeService.updateData(appTaskType);
        return DataReturn.ok();
    }

    @PostMapping("/search")
    @ApiOperation("条件查询+分页")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "当前页面", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "rows", value = "每页记录数", dataType = "int", paramType = "query")})
    public DataReturn findListByPage(@RequestBody(required = false) AppTaskType appTaskType, Integer page,
                                     Integer pageCount) {
        IPage<AppTaskType> appTaskTypePage = appTaskTypeService.findListByPage(appTaskType, page, pageCount);
        Map<String, Object> retMap = new HashMap<String, Object>();
        retMap.put("appTaskType", appTaskTypePage.getRecords());
        retMap.put("total", appTaskTypePage.getTotal());
        return DataReturn.ok(retMap);
    }

    @PostMapping("/searchNoPage")
    @ApiOperation("条件查询")
    public DataReturn searchNoPage(@RequestBody(required = false) AppTaskType appTaskType) {
        List<AppTaskType> appTaskTypeList = appTaskTypeService.searchNoPage(appTaskType);
        return DataReturn.ok(appTaskTypeList);
    }

    @GetMapping("/searchNoPageForFeign")
    @ApiOperation("条件查询")
    public DataReturn searchNoPageForFeign() {
        List<AppTaskType> appTaskTypeList = appTaskTypeService.searchNoPage(new AppTaskType());
        return DataReturn.ok(appTaskTypeList);
    }

    @GetMapping("/findOne/{id}")
    @ApiOperation("根据id获取配置实体")
    @ApiImplicitParam(name = "id", value = "配置ID", paramType = "path", dataType = "Long")
    public DataReturn findById(@PathVariable Integer id) {
        AppTaskType appTaskType = appTaskTypeService.findById(id);
        return DataReturn.ok(appTaskType);
    }

    @GetMapping("/findHotport")
    @ApiOperation("热点任务类型")
    public DataReturn findHotport() {
        List<AppHotportTypeDto> appHotportTypeDtoList = appTaskTypeService.findHotport();
        return DataReturn.ok(appHotportTypeDtoList);
    }

}